package web;

import lombok.Data;

import java.util.List;

/**
 * @author malguy-wang sir
 * @create ---
 */
//封装分页信息
@Data
public class Page<T> {
    //当前第几页
    private int pageNo;
    //当前页的list
    private List<T> list;
    //每页显示多少记录
    private int pageSize;
    //共多少条记录
    private long totalNun;
    //构造器初始化pageNo
    public Page(int pageNo) {
        this.pageNo = pageNo;
    }
    //获取总页数
    public int getTotalPageNum() {
        int totalPageNumber = (int)totalNun/pageSize;
        //如果分为一页一页后还有剩,说明还有剩余一页
        if(totalPageNumber%pageSize!=0) totalPageNumber++;
        return totalPageNumber;
    }
    //校验,防止bug
    public int getPageNo() {
        if(getPageNo()<0) pageNo=1;
        //大于总页数
        if(getPageNo()>getTotalPageNum()) pageNo=getTotalPageNum();
        return getPageNo();
    }
    //有没有下一页
    public boolean hasNextPage(){
        if(getPageNo()<getTotalPageNum()) return true;
        return false;
    }
    //有没有下一页
    public boolean hasPrePage(){
        if(getPageNo()>0) return true;
        return false;
    }
    public int getPrePage(){
        if(hasPrePage()) return getPageNo()+1;
        return getPageNo();
    }
}
